package edu.cmu.fithub.formbeans;

import java.util.ArrayList;
import java.util.List;
import java.util.TimeZone;

import org.mybeans.form.FormBean;

public class RegisterOpenIdForm extends FormBean {

	private String age;
	private String firstName;
	private String lastName;
	private String timeZone;
	private String email;
	private String weight;
	private String action;
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}


	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}


	public String getTimeZone() {
		return timeZone;
	}

	public void setTimeZone(String timeZone) {
		this.timeZone = timeZone;
	}

	public String getWeight() {
		return weight;
	}

	public void setWeight(String weight) {
		this.weight = weight;
	}



	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();

		if (email == null || email.length() == 0) {
		
			errors.add("Email is required");
		} else {
			if (email.matches(".*[<>\"].*")) {
				errors.add("Email may not contain angle brackets or quotes");
			}
			if (!email.contains("@")) {
				errors.add("Not a valid email");
			}
		}
		
		if (firstName == null || firstName.length() == 0) {
			errors.add("First Name is required");
		} else if (firstName.matches(".*[<>\"].*")) {
			errors.add("First Name may not contain angle brackets or quotes");
		}
		if (lastName == null || lastName.length() == 0) {
			errors.add("Last Name is required");
		} else if (lastName.matches(".*[<>\"].*")) {
			errors.add("Last Name may not contain angle brackets or quotes");
		}
		if (age == null || age.length() == 0) {
			errors.add("Age is required");
		} else if (!age.matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+")) {
			errors.add("Age must be a valid number");
		}
		if (weight == null || weight.length() == 0) {
			errors.add("Weight is required");
		} else if (!weight.matches("((-|\\+)?[0-9]+(\\.[0-9]+)?)+")) {
			errors.add("Weight must be a valid number");
		}

		
		if (timeZone == null || timeZone.length() == 0) {
			errors.add("Time Zone is required");
		} else {
			TimeZone tZone = TimeZone.getTimeZone(timeZone.trim());
			if ((!timeZone.equals("GMT") && (tZone.getID().equals("GMT")))) {
				errors.add("Time Zone is invalid");
			}
		}

		return errors;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getEmail() {
		return email;
	}
}
